<template>
	<view class="tabbar-frame">
		<view class="placeholder">

		</view>
		<view class="tabbar-content">
			<view class="tabbar-item" v-for="(item, index) in tabbarList" :key="index"
				@click="clickTabbar(item.path,index)">
				<view class="tabbar-icon" v-if="item.text">
					<image :src="item.icon" mode=""></image>
					<view class="superscript" v-if="item.text === '购物车'">
						<uv-badge type="error" max="99" :value="5" bgColor="#cda153"></uv-badge>
					</view>
				</view>
				<view class="tabbar-icon2" v-else>
					<image :src="item.icon" mode=""></image>
				</view>
				<view class="tabbar-text" :class="{ 'active-text': currentIndex === index }">{{ item.text }}</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		name: "tabbar",
		data() {
			return {
				tabbarList: [{
						text: '首页',
						icon: require('../../static/tabbar/home.png'),
						path: (`pages/index/index`)
					},
					{
						text: '分类',
						icon: require('../../static/tabbar/class.png'),
						path: (`pages/class/class`)
					},
					{
						text: '',
						icon: require('../../static/tabbar/center.png'),
						path: (`pages/index/index`)


					},
					{
						text: '购物车',
						icon: require('../../static/tabbar/cart.png'),
						path: (`pages/cart/cart`)
					},
					{
						text: '我的',
						icon: require('../../static/tabbar/me.png'),
						path: (`pages/me/me`)
					},
				]
			};
		},
		props: {
			currentIndex: {
				type: Number,
				default: 0
			}
		},
		methods: {
			clickTabbar(path, index) {
				uni.switchTab({
					url: `/${path}`
				})

			}
		}
	}
</script>
<style lang="scss" scoped>
	.placeholder {
		height: calc(60px + env(safe-area-inset-bottom) + 30rpx);
	}

	.tabbar-content {
		width: calc(100vw - 60rpx);
		padding: 0 30rpx;
		height: 60px;
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: #fff;
		padding-bottom: env(safe-area-inset-bottom);
		z-index: 10;
		box-shadow: 0 0 3px -1px gray;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 14px;

		.tabbar-item {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;

			.tabbar-icon {
				width: 20px;
				height: 20px;
				position: relative;

				image {
					width: 100%;
					height: 100%;
				}

				.superscript {
					position: absolute;
					bottom: 100%;
					left: 100%;
					transform: translate(-50%, 50%);
				}


			}

			.tabbar-icon2 {
				width: 40px;
				height: 40px;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.tabbar-text {
				margin-top: 5rpx;
			}

			.active-text {
				color: #42C3BF;
			}
		}
	}
</style>